package ph.com.gs3.formalistics.view.document.abstractfields;

import java.util.List;

import ph.com.gs3.formalistics.model.vo.business.form.FormFieldData;
import android.content.Context;

public abstract class GroupTypeFieldView extends AbstractFieldView {

	protected FormFieldData formField;

	public GroupTypeFieldView(Context context, FormFieldData formField) {
		super(context, formField.getId());
		super.setEnabled(formField.isEnabled());

		this.formField = formField;
		validateFieldsWithOptions(formField);

		createLabeledDefaultContainer(formField.getLabel(), getFieldId() + "_container");
	}

	protected void validateFieldsWithOptions(FormFieldData formField) {

		List<String> options = formField.getOptions();

		if (options == null) {
			throw new IllegalStateException("This field (" + formField.getId()
			        + ") must have an options property. It cannot be null.");
		} else if (options.size() <= 0) {
			throw new IllegalStateException("This field (" + formField.getId()
			        + ") must have a non empty options property.");
		}

	}

}
